package com.wdj.creation.singleton.volatileSingleton;

import com.wdj.creation.singleton.staticfactory.Singleton;

/**
 * @ClassName Singtelon
 * @Description
 * @Author wdj
 * @Date 2020/8/22 11:12
 * @Version 1.0
 **/
public class Singtelon {
    private volatile static Singtelon singtelon = null;
    private Singtelon(){}
    public static Singtelon getInstance(){
        if(singtelon == null){
            synchronized (Singtelon.class){
                if (singtelon==null){
                    if (singtelon == null){
                        singtelon = new Singtelon();
                    }
                }
            }
        }
        return singtelon;
    }
    public static void main(String[] args) {
        Singleton singleton1 = Singleton.getInstance();
        Singleton singleton2 = Singleton.getInstance();
        System.out.println(singleton1 == singleton2);
        System.out.println(singleton1.equals(singleton2));

    }
}
